#!/usr/bin/env node

const commander = require('commander')

const inquirer = require('inquirer')

const path = require('path')

const fs = require('fs')

const opt = [
    {
        type: 'input',
        message: '请输入您的姓名',
        name: "name",
        default: '淫东'
    },
    {
        type: 'list',
        message: '请选择您的性别',
        name: "sex",
        choices: ['男', "女", "祝晓东"]
    },
    {
        type: 'confirm',
        message: '您的选择',
        name: 'isOk',
        prefix: '是否确定', // 提示前缀
        suffix: '快选 祝晓东' // 提示后缀
    },
    {
        type: 'checkbox', // 类型为对选
        message: "请选择您的爱好",
        name: 'hobby',
        choices: ['抽烟',"喝酒","烫头"]
    },
    {
        type: 'expand', // 类型为模糊搜索
        message: '水果',
        name: 'fruits',
        choices: [
            {
                key: 'a',
                name: '苹果',
                value: "apple"
            },
            {
                key: 'c',
                name: '红苹果',
                value: "applered"
            },
            {
                key: 'd',
                name: '苹果12',
                value: "apple12"
            },
            {
                key: 'b',
                name: "香蕉",
                value: "banban"
            }
        ]

    }
]


// 搜集用户信息
commander.command('info') // 自定义指令
.description('搜集用户信息')
.action(() => {
    inquirer.prompt(opt).then(res => {
        console.log(res)
    })
})



const V = () => {
    let obj = fs.readFileSync(path.join(__dirname, 'package.json')).toString()

    obj = JSON.parse(obj)

    return obj.version
}

commander.version(V())
.parse(process.argv)
